package com.shop.util;

import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;

public class WriteStream {
	ByteArrayOutputStream bos;
	DataOutputStream dos;
	
	public WriteStream()
	{
		this.bos = new ByteArrayOutputStream();
		this.dos = new DataOutputStream(this.bos);
	}
	
	public void reset() {
		this.bos.reset();
	}
	
	public void flush() throws IOException {
		this.dos.flush();
	}
	
	public int size() {
		return this.dos.size();
	}
	
	public void write(final byte[] b, final int off, final int len) throws IOException {
		this.dos.write(b,off,len);
	}
	
	public void write(final int b) throws IOException {
		this.dos.write(b);
	}
	
	public void 	write(final byte[] b) throws IOException {
		this.dos.write(b);
	}
	public void	writeBoolean(final boolean v) throws IOException {
		this.dos.writeBoolean(v);
	}
	
	public void	writeByte(final int v) throws IOException {
		this.dos.writeByte(v);
	}
	
	public void writeBytes(final String s) throws IOException {
		this.dos.writeBytes(s);
	}
	
	public void writeChar(final int v) throws IOException {
		this.dos.writeChar(v);
	}
	
	public void writeChars(final String s) throws IOException {
		this.dos.writeChars(s);
	}
	
	public void writeDouble(final double v) throws IOException {
		this.dos.writeDouble(v);
	}
	
	public void writeFloat(final float v) throws IOException {
		this.dos.writeFloat(v);
	}
	
	public void writeInt(final int v) throws IOException {
		this.dos.writeInt(v);
	}
	
	public void writeLong(final long v) throws IOException {
		this.dos.writeLong(v);
	}
	
	public void writeShort(final int v) throws IOException {
		this.dos.writeShort(v);
	}
	
	public void writeUTF(final String str) throws IOException{
		this.dos.writeUTF(str);
	}
	
	public byte[] toByteArray() {
		return this.bos.toByteArray();
	}
	
	public void close() throws IOException {
		this.dos.close();
		this.bos.close();
	}	
	public static void main(String[] args) {
		WriteStream ws=new WriteStream();
		WriteStream ws1=new WriteStream();
		
		
		
		
		
		try {
//			ws.writeInt(5);
			ws.write(null);
			byte[] b=ws.toByteArray();
			byte[] b2=ws.toByteArray();
			ws.reset();
			ws.write("5".getBytes());
			System.out.println(b.length);
//			System.out.println(ws1.toByteArray().length);
			
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
}
